{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "## 线性回归的简洁实现"
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 数据集"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "import torch as tc\n",
    "from IPython import display\n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as  np \n",
    "import random\n",
    "import time"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "# W=[2,-3.4] b=4.3\n",
    "# y=Xw+b+e e belongs to a normalized distribution with 0 mean 0.01 standard error\n",
    "tc.set_default_dtype(tc.float64)\n",
    "device=tc.device('cuda' if tc.cuda.is_available() else 'cpu')\n",
    "print(device)\n",
    "num_inputs=2\n",
    "num_examples=1000\n",
    "\n",
    "true_w=[2,-3.4]\n",
    "true_b=4.2\n",
    "\n",
    "# features=tc.from_numpy(np.random.normal(0,1,(num_examples,num_inputs))) # 生成干扰项\n",
    "features=tc.from_numpy(np.random.normal(0,1,(num_examples,num_inputs))).to(device) # 生成干扰项\n",
    "labels= true_w[0]*features[:,0]+true_w[1]*features[:,1]+true_b\n",
    "# labels+=tc.from_numpy(np.random.normal(0,0.01,size=labels.size()))\n",
    "labels+=tc.from_numpy(np.random.normal(0,0.01,size=labels.size())).to(device)\n",
    "# labels.cuda()\n",
    "# features.float()\n",
    "# labels.float()\n",
    "# print(features[0],labels[0])\n",
    "# print(features.dtype)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "cuda\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "import torch.utils.data as Data"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "source": [
    "batch_size=10\n",
    "\n",
    "dataset=Data.TensorDataset(features,labels)\n",
    "\n",
    "data_iter=Data.DataLoader(dataset,batch_size,shuffle=True)"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "for X,y in data_iter:\n",
    "    print(X,y)\n",
    "    break"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "tensor([[-0.1673, -0.7370],\n",
      "        [-0.6966, -0.9863],\n",
      "        [ 0.6483,  0.6592],\n",
      "        [ 0.4459,  0.4714],\n",
      "        [ 1.6709, -0.2281],\n",
      "        [-1.3540, -0.8341],\n",
      "        [ 2.2948,  1.5390],\n",
      "        [ 0.5132, -1.1101],\n",
      "        [ 1.1760, -1.0608],\n",
      "        [-0.2682,  0.2523]], device='cuda:0') tensor([ 6.3789,  6.1510,  3.2536,  3.4762,  8.3339,  4.3121,  3.5642,  9.0014,\n",
      "        10.1537,  2.8105], device='cuda:0')\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "source": [
    "import torch.nn as nn"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "class LinearNet(nn.Module):\n",
    "    def __init__(self,n_feature):\n",
    "        super(LinearNet,self).__init__()\n",
    "        self.linear=nn.Linear(n_feature,1)\n",
    "    def forward(self,x):\n",
    "        y=self.linear(x)\n",
    "        return y\n",
    "net=LinearNet(num_inputs)\n",
    "# print(net.cuda())\n",
    "# print(net.device)"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "from torch.nn import init\n"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "source": [
    "init.normal_(net.linear.weight,mean=0,std=0.01)\n",
    "init.constant_(net.linear.bias,val=0)\n",
    "\n",
    "# print(net.linear.weight.dtype)\n",
    "# net.linear.weight.double()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "Parameter containing:\n",
       "tensor([0.], requires_grad=True)"
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "loss=nn.MSELoss()"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "source": [
    "import torch.optim as optim"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "source": [
    "optimizer = optim.SGD(net.parameters(),lr=0.03)"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "source": [
    "num_epochs=1000\n",
    "net.cuda()\n",
    "start=time.time()\n",
    "for epoch in range(1,num_epochs+1):\n",
    "    epoch_time=time.time()\n",
    "    for X,y in data_iter:\n",
    "        out=net(X)\n",
    "        l=loss(out,y.view(-1,1))\n",
    "        optimizer.zero_grad()\n",
    "        l.backward()\n",
    "        optimizer.step()\n",
    "    print('epoch %d,loss %f cost %.4f' % (epoch+1,l.item(),time.time()-epoch_time))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "epoch 2,loss 0.000493 cost 0.5281\n",
      "epoch 3,loss 0.000038 cost 0.0256\n",
      "epoch 4,loss 0.000087 cost 0.0265\n",
      "epoch 5,loss 0.000041 cost 0.0253\n",
      "epoch 6,loss 0.000070 cost 0.0263\n",
      "epoch 7,loss 0.000205 cost 0.0256\n",
      "epoch 8,loss 0.000318 cost 0.0251\n",
      "epoch 9,loss 0.000251 cost 0.0253\n",
      "epoch 10,loss 0.000071 cost 0.0261\n",
      "epoch 11,loss 0.000048 cost 0.0276\n",
      "epoch 12,loss 0.000117 cost 0.0263\n",
      "epoch 13,loss 0.000090 cost 0.0262\n",
      "epoch 14,loss 0.000051 cost 0.0265\n",
      "epoch 15,loss 0.000138 cost 0.0311\n",
      "epoch 16,loss 0.000041 cost 0.0313\n",
      "epoch 17,loss 0.000101 cost 0.0301\n",
      "epoch 18,loss 0.000114 cost 0.0302\n",
      "epoch 19,loss 0.000151 cost 0.0279\n",
      "epoch 20,loss 0.000077 cost 0.0265\n",
      "epoch 21,loss 0.000056 cost 0.0257\n",
      "epoch 22,loss 0.000035 cost 0.0259\n",
      "epoch 23,loss 0.000182 cost 0.0292\n",
      "epoch 24,loss 0.000092 cost 0.0276\n",
      "epoch 25,loss 0.000131 cost 0.0269\n",
      "epoch 26,loss 0.000042 cost 0.0317\n",
      "epoch 27,loss 0.000070 cost 0.0284\n",
      "epoch 28,loss 0.000058 cost 0.0278\n",
      "epoch 29,loss 0.000101 cost 0.0254\n",
      "epoch 30,loss 0.000141 cost 0.0258\n",
      "epoch 31,loss 0.000066 cost 0.0274\n",
      "epoch 32,loss 0.000054 cost 0.0254\n",
      "epoch 33,loss 0.000098 cost 0.0288\n",
      "epoch 34,loss 0.000088 cost 0.0270\n",
      "epoch 35,loss 0.000135 cost 0.0303\n",
      "epoch 36,loss 0.000144 cost 0.0271\n",
      "epoch 37,loss 0.000103 cost 0.0260\n",
      "epoch 38,loss 0.000149 cost 0.0258\n",
      "epoch 39,loss 0.000059 cost 0.0263\n",
      "epoch 40,loss 0.000076 cost 0.0261\n",
      "epoch 41,loss 0.000104 cost 0.0264\n",
      "epoch 42,loss 0.000040 cost 0.0275\n",
      "epoch 43,loss 0.000161 cost 0.0275\n",
      "epoch 44,loss 0.000072 cost 0.0266\n",
      "epoch 45,loss 0.000090 cost 0.0262\n",
      "epoch 46,loss 0.000088 cost 0.0264\n",
      "epoch 47,loss 0.000094 cost 0.0260\n",
      "epoch 48,loss 0.000233 cost 0.0261\n",
      "epoch 49,loss 0.000078 cost 0.0259\n",
      "epoch 50,loss 0.000088 cost 0.0268\n",
      "epoch 51,loss 0.000109 cost 0.0272\n",
      "epoch 52,loss 0.000077 cost 0.0260\n",
      "epoch 53,loss 0.000136 cost 0.0259\n",
      "epoch 54,loss 0.000064 cost 0.0283\n",
      "epoch 55,loss 0.000129 cost 0.0270\n",
      "epoch 56,loss 0.000252 cost 0.0265\n",
      "epoch 57,loss 0.000049 cost 0.0262\n",
      "epoch 58,loss 0.000177 cost 0.0286\n",
      "epoch 59,loss 0.000152 cost 0.0297\n",
      "epoch 60,loss 0.000232 cost 0.0282\n",
      "epoch 61,loss 0.000090 cost 0.0258\n",
      "epoch 62,loss 0.000091 cost 0.0260\n",
      "epoch 63,loss 0.000157 cost 0.0271\n",
      "epoch 64,loss 0.000050 cost 0.0262\n",
      "epoch 65,loss 0.000078 cost 0.0284\n",
      "epoch 66,loss 0.000033 cost 0.0265\n",
      "epoch 67,loss 0.000117 cost 0.0275\n",
      "epoch 68,loss 0.000034 cost 0.0285\n",
      "epoch 69,loss 0.000128 cost 0.0278\n",
      "epoch 70,loss 0.000049 cost 0.0257\n",
      "epoch 71,loss 0.000072 cost 0.0257\n",
      "epoch 72,loss 0.000090 cost 0.0277\n",
      "epoch 73,loss 0.000096 cost 0.0260\n",
      "epoch 74,loss 0.000146 cost 0.0293\n",
      "epoch 75,loss 0.000072 cost 0.0289\n",
      "epoch 76,loss 0.000095 cost 0.0328\n",
      "epoch 77,loss 0.000129 cost 0.0326\n",
      "epoch 78,loss 0.000103 cost 0.0270\n",
      "epoch 79,loss 0.000074 cost 0.0264\n",
      "epoch 80,loss 0.000147 cost 0.0250\n",
      "epoch 81,loss 0.000070 cost 0.0248\n",
      "epoch 82,loss 0.000039 cost 0.0288\n",
      "epoch 83,loss 0.000155 cost 0.0263\n",
      "epoch 84,loss 0.000083 cost 0.0253\n",
      "epoch 85,loss 0.000056 cost 0.0249\n",
      "epoch 86,loss 0.000050 cost 0.0247\n",
      "epoch 87,loss 0.000101 cost 0.0259\n",
      "epoch 88,loss 0.000070 cost 0.0249\n",
      "epoch 89,loss 0.000043 cost 0.0283\n",
      "epoch 90,loss 0.000032 cost 0.0322\n",
      "epoch 91,loss 0.000077 cost 0.0286\n",
      "epoch 92,loss 0.000102 cost 0.0282\n",
      "epoch 93,loss 0.000094 cost 0.0254\n",
      "epoch 94,loss 0.000143 cost 0.0259\n",
      "epoch 95,loss 0.000095 cost 0.0253\n",
      "epoch 96,loss 0.000129 cost 0.0249\n",
      "epoch 97,loss 0.000108 cost 0.0261\n",
      "epoch 98,loss 0.000132 cost 0.0267\n",
      "epoch 99,loss 0.000080 cost 0.0276\n",
      "epoch 100,loss 0.000079 cost 0.0267\n",
      "epoch 101,loss 0.000074 cost 0.0248\n",
      "epoch 102,loss 0.000089 cost 0.0258\n",
      "epoch 103,loss 0.000034 cost 0.0253\n",
      "epoch 104,loss 0.000109 cost 0.0249\n",
      "epoch 105,loss 0.000191 cost 0.0249\n",
      "epoch 106,loss 0.000105 cost 0.0273\n",
      "epoch 107,loss 0.000188 cost 0.0267\n",
      "epoch 108,loss 0.000056 cost 0.0250\n",
      "epoch 109,loss 0.000062 cost 0.0249\n",
      "epoch 110,loss 0.000062 cost 0.0251\n",
      "epoch 111,loss 0.000067 cost 0.0261\n",
      "epoch 112,loss 0.000160 cost 0.0256\n",
      "epoch 113,loss 0.000122 cost 0.0253\n",
      "epoch 114,loss 0.000031 cost 0.0278\n",
      "epoch 115,loss 0.000158 cost 0.0263\n",
      "epoch 116,loss 0.000078 cost 0.0257\n",
      "epoch 117,loss 0.000080 cost 0.0248\n",
      "epoch 118,loss 0.000262 cost 0.0250\n",
      "epoch 119,loss 0.000122 cost 0.0255\n",
      "epoch 120,loss 0.000175 cost 0.0262\n",
      "epoch 121,loss 0.000176 cost 0.0255\n",
      "epoch 122,loss 0.000107 cost 0.0270\n",
      "epoch 123,loss 0.000054 cost 0.0270\n",
      "epoch 124,loss 0.000094 cost 0.0249\n",
      "epoch 125,loss 0.000059 cost 0.0271\n",
      "epoch 126,loss 0.000096 cost 0.0263\n",
      "epoch 127,loss 0.000127 cost 0.0251\n",
      "epoch 128,loss 0.000111 cost 0.0259\n",
      "epoch 129,loss 0.000068 cost 0.0258\n",
      "epoch 130,loss 0.000129 cost 0.0255\n",
      "epoch 131,loss 0.000205 cost 0.0279\n",
      "epoch 132,loss 0.000078 cost 0.0255\n",
      "epoch 133,loss 0.000112 cost 0.0248\n",
      "epoch 134,loss 0.000160 cost 0.0247\n",
      "epoch 135,loss 0.000095 cost 0.0247\n",
      "epoch 136,loss 0.000219 cost 0.0247\n",
      "epoch 137,loss 0.000039 cost 0.0259\n",
      "epoch 138,loss 0.000134 cost 0.0261\n",
      "epoch 139,loss 0.000051 cost 0.0288\n",
      "epoch 140,loss 0.000109 cost 0.0257\n",
      "epoch 141,loss 0.000111 cost 0.0259\n",
      "epoch 142,loss 0.000074 cost 0.0270\n",
      "epoch 143,loss 0.000050 cost 0.0250\n",
      "epoch 144,loss 0.000132 cost 0.0248\n",
      "epoch 145,loss 0.000077 cost 0.0253\n",
      "epoch 146,loss 0.000079 cost 0.0268\n",
      "epoch 147,loss 0.000249 cost 0.0279\n",
      "epoch 148,loss 0.000109 cost 0.0266\n",
      "epoch 149,loss 0.000073 cost 0.0256\n",
      "epoch 150,loss 0.000218 cost 0.0251\n",
      "epoch 151,loss 0.000031 cost 0.0250\n",
      "epoch 152,loss 0.000166 cost 0.0248\n",
      "epoch 153,loss 0.000105 cost 0.0248\n",
      "epoch 154,loss 0.000121 cost 0.0265\n",
      "epoch 155,loss 0.000083 cost 0.0279\n",
      "epoch 156,loss 0.000125 cost 0.0269\n",
      "epoch 157,loss 0.000122 cost 0.0261\n",
      "epoch 158,loss 0.000128 cost 0.0253\n",
      "epoch 159,loss 0.000089 cost 0.0254\n",
      "epoch 160,loss 0.000077 cost 0.0252\n",
      "epoch 161,loss 0.000104 cost 0.0250\n",
      "epoch 162,loss 0.000036 cost 0.0259\n",
      "epoch 163,loss 0.000159 cost 0.0259\n",
      "epoch 164,loss 0.000073 cost 0.0253\n",
      "epoch 165,loss 0.000126 cost 0.0261\n",
      "epoch 166,loss 0.000090 cost 0.0251\n",
      "epoch 167,loss 0.000065 cost 0.0250\n",
      "epoch 168,loss 0.000106 cost 0.0264\n",
      "epoch 169,loss 0.000090 cost 0.0262\n",
      "epoch 170,loss 0.000099 cost 0.0277\n",
      "epoch 171,loss 0.000109 cost 0.0309\n",
      "epoch 172,loss 0.000130 cost 0.0300\n",
      "epoch 173,loss 0.000148 cost 0.0276\n",
      "epoch 174,loss 0.000083 cost 0.0284\n",
      "epoch 175,loss 0.000260 cost 0.0277\n",
      "epoch 176,loss 0.000062 cost 0.0252\n",
      "epoch 177,loss 0.000077 cost 0.0251\n",
      "epoch 178,loss 0.000132 cost 0.0283\n",
      "epoch 179,loss 0.000119 cost 0.0266\n",
      "epoch 180,loss 0.000016 cost 0.0255\n",
      "epoch 181,loss 0.000131 cost 0.0255\n",
      "epoch 182,loss 0.000120 cost 0.0248\n",
      "epoch 183,loss 0.000082 cost 0.0257\n",
      "epoch 184,loss 0.000092 cost 0.0252\n",
      "epoch 185,loss 0.000084 cost 0.0248\n",
      "epoch 186,loss 0.000051 cost 0.0257\n",
      "epoch 187,loss 0.000047 cost 0.0276\n",
      "epoch 188,loss 0.000139 cost 0.0270\n",
      "epoch 189,loss 0.000130 cost 0.0272\n",
      "epoch 190,loss 0.000100 cost 0.0259\n",
      "epoch 191,loss 0.000087 cost 0.0270\n",
      "epoch 192,loss 0.000127 cost 0.0251\n",
      "epoch 193,loss 0.000105 cost 0.0271\n",
      "epoch 194,loss 0.000079 cost 0.0293\n",
      "epoch 195,loss 0.000127 cost 0.0284\n",
      "epoch 196,loss 0.000029 cost 0.0261\n",
      "epoch 197,loss 0.000051 cost 0.0251\n",
      "epoch 198,loss 0.000148 cost 0.0249\n",
      "epoch 199,loss 0.000146 cost 0.0249\n",
      "epoch 200,loss 0.000100 cost 0.0254\n",
      "epoch 201,loss 0.000093 cost 0.0272\n",
      "epoch 202,loss 0.000091 cost 0.0265\n",
      "epoch 203,loss 0.000032 cost 0.0281\n",
      "epoch 204,loss 0.000052 cost 0.0269\n",
      "epoch 205,loss 0.000058 cost 0.0280\n",
      "epoch 206,loss 0.000103 cost 0.0298\n",
      "epoch 207,loss 0.000101 cost 0.0279\n",
      "epoch 208,loss 0.000124 cost 0.0255\n",
      "epoch 209,loss 0.000096 cost 0.0270\n",
      "epoch 210,loss 0.000059 cost 0.0306\n",
      "epoch 211,loss 0.000163 cost 0.0290\n",
      "epoch 212,loss 0.000116 cost 0.0260\n",
      "epoch 213,loss 0.000049 cost 0.0253\n",
      "epoch 214,loss 0.000104 cost 0.0258\n",
      "epoch 215,loss 0.000029 cost 0.0247\n",
      "epoch 216,loss 0.000128 cost 0.0247\n",
      "epoch 217,loss 0.000058 cost 0.0249\n",
      "epoch 218,loss 0.000060 cost 0.0252\n",
      "epoch 219,loss 0.000088 cost 0.0254\n",
      "epoch 220,loss 0.000090 cost 0.0248\n",
      "epoch 221,loss 0.000115 cost 0.0248\n",
      "epoch 222,loss 0.000289 cost 0.0247\n",
      "epoch 223,loss 0.000130 cost 0.0246\n",
      "epoch 224,loss 0.000129 cost 0.0274\n",
      "epoch 225,loss 0.000034 cost 0.0250\n",
      "epoch 226,loss 0.000212 cost 0.0249\n",
      "epoch 227,loss 0.000015 cost 0.0256\n",
      "epoch 228,loss 0.000130 cost 0.0248\n",
      "epoch 229,loss 0.000059 cost 0.0247\n",
      "epoch 230,loss 0.000148 cost 0.0246\n",
      "epoch 231,loss 0.000132 cost 0.0246\n",
      "epoch 232,loss 0.000079 cost 0.0253\n",
      "epoch 233,loss 0.000073 cost 0.0253\n",
      "epoch 234,loss 0.000184 cost 0.0251\n",
      "epoch 235,loss 0.000108 cost 0.0263\n",
      "epoch 236,loss 0.000085 cost 0.0277\n",
      "epoch 237,loss 0.000143 cost 0.0249\n",
      "epoch 238,loss 0.000062 cost 0.0248\n",
      "epoch 239,loss 0.000155 cost 0.0248\n",
      "epoch 240,loss 0.000136 cost 0.0248\n",
      "epoch 241,loss 0.000076 cost 0.0247\n",
      "epoch 242,loss 0.000090 cost 0.0246\n",
      "epoch 243,loss 0.000115 cost 0.0248\n",
      "epoch 244,loss 0.000122 cost 0.0260\n",
      "epoch 245,loss 0.000216 cost 0.0270\n",
      "epoch 246,loss 0.000113 cost 0.0249\n",
      "epoch 247,loss 0.000130 cost 0.0249\n",
      "epoch 248,loss 0.000072 cost 0.0250\n",
      "epoch 249,loss 0.000083 cost 0.0254\n",
      "epoch 250,loss 0.000128 cost 0.0253\n",
      "epoch 251,loss 0.000058 cost 0.0278\n",
      "epoch 252,loss 0.000110 cost 0.0270\n",
      "epoch 253,loss 0.000318 cost 0.0264\n",
      "epoch 254,loss 0.000222 cost 0.0280\n",
      "epoch 255,loss 0.000081 cost 0.0265\n",
      "epoch 256,loss 0.000110 cost 0.0257\n",
      "epoch 257,loss 0.000137 cost 0.0254\n",
      "epoch 258,loss 0.000052 cost 0.0252\n",
      "epoch 259,loss 0.000045 cost 0.0263\n",
      "epoch 260,loss 0.000042 cost 0.0274\n",
      "epoch 261,loss 0.000171 cost 0.0256\n",
      "epoch 262,loss 0.000165 cost 0.0255\n",
      "epoch 263,loss 0.000086 cost 0.0248\n",
      "epoch 264,loss 0.000223 cost 0.0256\n",
      "epoch 265,loss 0.000086 cost 0.0265\n",
      "epoch 266,loss 0.000118 cost 0.0260\n",
      "epoch 267,loss 0.000140 cost 0.0276\n",
      "epoch 268,loss 0.000133 cost 0.0299\n",
      "epoch 269,loss 0.000074 cost 0.0250\n",
      "epoch 270,loss 0.000258 cost 0.0255\n",
      "epoch 271,loss 0.000127 cost 0.0248\n",
      "epoch 272,loss 0.000075 cost 0.0251\n",
      "epoch 273,loss 0.000168 cost 0.0250\n",
      "epoch 274,loss 0.000113 cost 0.0247\n",
      "epoch 275,loss 0.000090 cost 0.0252\n",
      "epoch 276,loss 0.000095 cost 0.0270\n",
      "epoch 277,loss 0.000126 cost 0.0253\n",
      "epoch 278,loss 0.000064 cost 0.0253\n",
      "epoch 279,loss 0.000143 cost 0.0252\n",
      "epoch 280,loss 0.000103 cost 0.0252\n",
      "epoch 281,loss 0.000189 cost 0.0249\n",
      "epoch 282,loss 0.000046 cost 0.0247\n",
      "epoch 283,loss 0.000088 cost 0.0254\n",
      "epoch 284,loss 0.000078 cost 0.0272\n",
      "epoch 285,loss 0.000057 cost 0.0254\n",
      "epoch 286,loss 0.000115 cost 0.0255\n",
      "epoch 287,loss 0.000050 cost 0.0259\n",
      "epoch 288,loss 0.000086 cost 0.0253\n",
      "epoch 289,loss 0.000115 cost 0.0251\n",
      "epoch 290,loss 0.000076 cost 0.0267\n",
      "epoch 291,loss 0.000083 cost 0.0440\n",
      "epoch 292,loss 0.000077 cost 0.0278\n",
      "epoch 293,loss 0.000059 cost 0.0255\n",
      "epoch 294,loss 0.000103 cost 0.0255\n",
      "epoch 295,loss 0.000081 cost 0.0249\n",
      "epoch 296,loss 0.000060 cost 0.0250\n",
      "epoch 297,loss 0.000149 cost 0.0249\n",
      "epoch 298,loss 0.000112 cost 0.0252\n",
      "epoch 299,loss 0.000068 cost 0.0260\n",
      "epoch 300,loss 0.000025 cost 0.0276\n",
      "epoch 301,loss 0.000200 cost 0.0271\n",
      "epoch 302,loss 0.000185 cost 0.0265\n",
      "epoch 303,loss 0.000096 cost 0.0251\n",
      "epoch 304,loss 0.000202 cost 0.0249\n",
      "epoch 305,loss 0.000148 cost 0.0252\n",
      "epoch 306,loss 0.000103 cost 0.0258\n",
      "epoch 307,loss 0.000156 cost 0.0256\n",
      "epoch 308,loss 0.000044 cost 0.0261\n",
      "epoch 309,loss 0.000147 cost 0.0249\n",
      "epoch 310,loss 0.000114 cost 0.0252\n",
      "epoch 311,loss 0.000102 cost 0.0250\n",
      "epoch 312,loss 0.000097 cost 0.0249\n",
      "epoch 313,loss 0.000207 cost 0.0247\n",
      "epoch 314,loss 0.000206 cost 0.0249\n",
      "epoch 315,loss 0.000116 cost 0.0246\n",
      "epoch 316,loss 0.000104 cost 0.0261\n",
      "epoch 317,loss 0.000081 cost 0.0247\n",
      "epoch 318,loss 0.000193 cost 0.0248\n",
      "epoch 319,loss 0.000144 cost 0.0246\n",
      "epoch 320,loss 0.000111 cost 0.0245\n",
      "epoch 321,loss 0.000032 cost 0.0269\n",
      "epoch 322,loss 0.000258 cost 0.0252\n",
      "epoch 323,loss 0.000161 cost 0.0247\n",
      "epoch 324,loss 0.000102 cost 0.0247\n",
      "epoch 325,loss 0.000128 cost 0.0278\n",
      "epoch 326,loss 0.000103 cost 0.0256\n",
      "epoch 327,loss 0.000092 cost 0.0249\n",
      "epoch 328,loss 0.000213 cost 0.0250\n",
      "epoch 329,loss 0.000054 cost 0.0250\n",
      "epoch 330,loss 0.000071 cost 0.0263\n",
      "epoch 331,loss 0.000051 cost 0.0254\n",
      "epoch 332,loss 0.000145 cost 0.0248\n",
      "epoch 333,loss 0.000118 cost 0.0260\n",
      "epoch 334,loss 0.000107 cost 0.0288\n",
      "epoch 335,loss 0.000017 cost 0.0279\n",
      "epoch 336,loss 0.000050 cost 0.0250\n",
      "epoch 337,loss 0.000037 cost 0.0250\n",
      "epoch 338,loss 0.000057 cost 0.0270\n",
      "epoch 339,loss 0.000036 cost 0.0253\n",
      "epoch 340,loss 0.000078 cost 0.0268\n",
      "epoch 341,loss 0.000136 cost 0.0268\n",
      "epoch 342,loss 0.000148 cost 0.0297\n",
      "epoch 343,loss 0.000088 cost 0.0271\n",
      "epoch 344,loss 0.000159 cost 0.0261\n",
      "epoch 345,loss 0.000124 cost 0.0261\n",
      "epoch 346,loss 0.000086 cost 0.0298\n",
      "epoch 347,loss 0.000037 cost 0.0336\n",
      "epoch 348,loss 0.000127 cost 0.0297\n",
      "epoch 349,loss 0.000048 cost 0.0291\n",
      "epoch 350,loss 0.000047 cost 0.0288\n",
      "epoch 351,loss 0.000109 cost 0.0257\n",
      "epoch 352,loss 0.000157 cost 0.0266\n",
      "epoch 353,loss 0.000146 cost 0.0258\n",
      "epoch 354,loss 0.000041 cost 0.0268\n",
      "epoch 355,loss 0.000078 cost 0.0270\n",
      "epoch 356,loss 0.000126 cost 0.0284\n",
      "epoch 357,loss 0.000131 cost 0.0265\n",
      "epoch 358,loss 0.000039 cost 0.0262\n",
      "epoch 359,loss 0.000109 cost 0.0255\n",
      "epoch 360,loss 0.000063 cost 0.0254\n",
      "epoch 361,loss 0.000064 cost 0.0255\n",
      "epoch 362,loss 0.000131 cost 0.0251\n",
      "epoch 363,loss 0.000072 cost 0.0269\n",
      "epoch 364,loss 0.000102 cost 0.0274\n",
      "epoch 365,loss 0.000076 cost 0.0305\n",
      "epoch 366,loss 0.000080 cost 0.0273\n",
      "epoch 367,loss 0.000087 cost 0.0266\n",
      "epoch 368,loss 0.000103 cost 0.0257\n",
      "epoch 369,loss 0.000108 cost 0.0262\n",
      "epoch 370,loss 0.000065 cost 0.0278\n",
      "epoch 371,loss 0.000072 cost 0.0275\n",
      "epoch 372,loss 0.000082 cost 0.0288\n",
      "epoch 373,loss 0.000133 cost 0.0260\n",
      "epoch 374,loss 0.000048 cost 0.0266\n",
      "epoch 375,loss 0.000226 cost 0.0286\n",
      "epoch 376,loss 0.000121 cost 0.0273\n",
      "epoch 377,loss 0.000140 cost 0.0268\n",
      "epoch 378,loss 0.000172 cost 0.0283\n",
      "epoch 379,loss 0.000099 cost 0.0275\n",
      "epoch 380,loss 0.000115 cost 0.0279\n",
      "epoch 381,loss 0.000054 cost 0.0260\n",
      "epoch 382,loss 0.000086 cost 0.0273\n",
      "epoch 383,loss 0.000159 cost 0.0274\n",
      "epoch 384,loss 0.000143 cost 0.0256\n",
      "epoch 385,loss 0.000095 cost 0.0262\n",
      "epoch 386,loss 0.000112 cost 0.0270\n",
      "epoch 387,loss 0.000261 cost 0.0271\n",
      "epoch 388,loss 0.000056 cost 0.0299\n",
      "epoch 389,loss 0.000106 cost 0.0335\n",
      "epoch 390,loss 0.000180 cost 0.0296\n",
      "epoch 391,loss 0.000073 cost 0.0330\n",
      "epoch 392,loss 0.000057 cost 0.0278\n",
      "epoch 393,loss 0.000076 cost 0.0302\n",
      "epoch 394,loss 0.000068 cost 0.0328\n",
      "epoch 395,loss 0.000058 cost 0.0308\n",
      "epoch 396,loss 0.000093 cost 0.0272\n",
      "epoch 397,loss 0.000130 cost 0.0253\n",
      "epoch 398,loss 0.000077 cost 0.0266\n",
      "epoch 399,loss 0.000105 cost 0.0277\n",
      "epoch 400,loss 0.000198 cost 0.0246\n",
      "epoch 401,loss 0.000141 cost 0.0249\n",
      "epoch 402,loss 0.000178 cost 0.0272\n",
      "epoch 403,loss 0.000149 cost 0.0278\n",
      "epoch 404,loss 0.000183 cost 0.0288\n",
      "epoch 405,loss 0.000122 cost 0.0250\n",
      "epoch 406,loss 0.000045 cost 0.0263\n",
      "epoch 407,loss 0.000048 cost 0.0261\n",
      "epoch 408,loss 0.000152 cost 0.0253\n",
      "epoch 409,loss 0.000029 cost 0.0273\n",
      "epoch 410,loss 0.000074 cost 0.0273\n",
      "epoch 411,loss 0.000076 cost 0.0264\n",
      "epoch 412,loss 0.000069 cost 0.0289\n",
      "epoch 413,loss 0.000145 cost 0.0257\n",
      "epoch 414,loss 0.000104 cost 0.0258\n",
      "epoch 415,loss 0.000094 cost 0.0257\n",
      "epoch 416,loss 0.000131 cost 0.0252\n",
      "epoch 417,loss 0.000148 cost 0.0248\n",
      "epoch 418,loss 0.000109 cost 0.0256\n",
      "epoch 419,loss 0.000056 cost 0.0253\n",
      "epoch 420,loss 0.000129 cost 0.0291\n",
      "epoch 421,loss 0.000081 cost 0.0258\n",
      "epoch 422,loss 0.000292 cost 0.0255\n",
      "epoch 423,loss 0.000081 cost 0.0248\n",
      "epoch 424,loss 0.000096 cost 0.0251\n",
      "epoch 425,loss 0.000092 cost 0.0263\n",
      "epoch 426,loss 0.000087 cost 0.0265\n",
      "epoch 427,loss 0.000106 cost 0.0259\n",
      "epoch 428,loss 0.000131 cost 0.0282\n",
      "epoch 429,loss 0.000122 cost 0.0262\n",
      "epoch 430,loss 0.000071 cost 0.0258\n",
      "epoch 431,loss 0.000102 cost 0.0253\n",
      "epoch 432,loss 0.000076 cost 0.0251\n",
      "epoch 433,loss 0.000171 cost 0.0281\n",
      "epoch 434,loss 0.000078 cost 0.0256\n",
      "epoch 435,loss 0.000064 cost 0.0266\n",
      "epoch 436,loss 0.000120 cost 0.0269\n",
      "epoch 437,loss 0.000074 cost 0.0268\n",
      "epoch 438,loss 0.000151 cost 0.0269\n",
      "epoch 439,loss 0.000109 cost 0.0250\n",
      "epoch 440,loss 0.000081 cost 0.0251\n",
      "epoch 441,loss 0.000049 cost 0.0256\n",
      "epoch 442,loss 0.000052 cost 0.0269\n",
      "epoch 443,loss 0.000059 cost 0.0268\n",
      "epoch 444,loss 0.000139 cost 0.0277\n",
      "epoch 445,loss 0.000077 cost 0.0252\n",
      "epoch 446,loss 0.000206 cost 0.0248\n",
      "epoch 447,loss 0.000104 cost 0.0272\n",
      "epoch 448,loss 0.000116 cost 0.0251\n",
      "epoch 449,loss 0.000079 cost 0.0256\n",
      "epoch 450,loss 0.000035 cost 0.0265\n",
      "epoch 451,loss 0.000061 cost 0.0253\n",
      "epoch 452,loss 0.000030 cost 0.0256\n",
      "epoch 453,loss 0.000081 cost 0.0250\n",
      "epoch 454,loss 0.000127 cost 0.0265\n",
      "epoch 455,loss 0.000054 cost 0.0253\n",
      "epoch 456,loss 0.000079 cost 0.0254\n",
      "epoch 457,loss 0.000075 cost 0.0249\n",
      "epoch 458,loss 0.000063 cost 0.0250\n",
      "epoch 459,loss 0.000167 cost 0.0251\n",
      "epoch 460,loss 0.000140 cost 0.0267\n",
      "epoch 461,loss 0.000084 cost 0.0250\n",
      "epoch 462,loss 0.000083 cost 0.0249\n",
      "epoch 463,loss 0.000104 cost 0.0246\n",
      "epoch 464,loss 0.000164 cost 0.0257\n",
      "epoch 465,loss 0.000129 cost 0.0249\n",
      "epoch 466,loss 0.000044 cost 0.0251\n",
      "epoch 467,loss 0.000128 cost 0.0250\n",
      "epoch 468,loss 0.000133 cost 0.0269\n",
      "epoch 469,loss 0.000186 cost 0.0249\n",
      "epoch 470,loss 0.000076 cost 0.0276\n",
      "epoch 471,loss 0.000095 cost 0.0252\n",
      "epoch 472,loss 0.000075 cost 0.0278\n",
      "epoch 473,loss 0.000042 cost 0.0264\n",
      "epoch 474,loss 0.000082 cost 0.0277\n",
      "epoch 475,loss 0.000068 cost 0.0265\n",
      "epoch 476,loss 0.000069 cost 0.0262\n",
      "epoch 477,loss 0.000167 cost 0.0251\n",
      "epoch 478,loss 0.000056 cost 0.0260\n",
      "epoch 479,loss 0.000095 cost 0.0290\n",
      "epoch 480,loss 0.000111 cost 0.0257\n",
      "epoch 481,loss 0.000203 cost 0.0261\n",
      "epoch 482,loss 0.000046 cost 0.0266\n",
      "epoch 483,loss 0.000094 cost 0.0284\n",
      "epoch 484,loss 0.000043 cost 0.0280\n",
      "epoch 485,loss 0.000053 cost 0.0254\n",
      "epoch 486,loss 0.000072 cost 0.0251\n",
      "epoch 487,loss 0.000146 cost 0.0260\n",
      "epoch 488,loss 0.000113 cost 0.0253\n",
      "epoch 489,loss 0.000159 cost 0.0254\n",
      "epoch 490,loss 0.000178 cost 0.0250\n",
      "epoch 491,loss 0.000031 cost 0.0280\n",
      "epoch 492,loss 0.000084 cost 0.0279\n",
      "epoch 493,loss 0.000115 cost 0.0252\n",
      "epoch 494,loss 0.000127 cost 0.0256\n",
      "epoch 495,loss 0.000082 cost 0.0273\n",
      "epoch 496,loss 0.000117 cost 0.0253\n",
      "epoch 497,loss 0.000246 cost 0.0256\n",
      "epoch 498,loss 0.000085 cost 0.0273\n",
      "epoch 499,loss 0.000181 cost 0.0276\n",
      "epoch 500,loss 0.000051 cost 0.0261\n",
      "epoch 501,loss 0.000051 cost 0.0250\n",
      "epoch 502,loss 0.000072 cost 0.0269\n",
      "epoch 503,loss 0.000091 cost 0.0248\n",
      "epoch 504,loss 0.000107 cost 0.0250\n",
      "epoch 505,loss 0.000063 cost 0.0247\n",
      "epoch 506,loss 0.000098 cost 0.0254\n",
      "epoch 507,loss 0.000056 cost 0.0258\n",
      "epoch 508,loss 0.000147 cost 0.0277\n",
      "epoch 509,loss 0.000072 cost 0.0256\n",
      "epoch 510,loss 0.000189 cost 0.0256\n",
      "epoch 511,loss 0.000108 cost 0.0247\n",
      "epoch 512,loss 0.000161 cost 0.0249\n",
      "epoch 513,loss 0.000086 cost 0.0247\n",
      "epoch 514,loss 0.000043 cost 0.0254\n",
      "epoch 515,loss 0.000080 cost 0.0251\n",
      "epoch 516,loss 0.000072 cost 0.0261\n",
      "epoch 517,loss 0.000115 cost 0.0248\n",
      "epoch 518,loss 0.000120 cost 0.0255\n",
      "epoch 519,loss 0.000213 cost 0.0248\n",
      "epoch 520,loss 0.000057 cost 0.0250\n",
      "epoch 521,loss 0.000113 cost 0.0246\n",
      "epoch 522,loss 0.000081 cost 0.0254\n",
      "epoch 523,loss 0.000043 cost 0.0281\n",
      "epoch 524,loss 0.000104 cost 0.0302\n",
      "epoch 525,loss 0.000046 cost 0.0313\n",
      "epoch 526,loss 0.000142 cost 0.0296\n",
      "epoch 527,loss 0.000077 cost 0.0280\n",
      "epoch 528,loss 0.000076 cost 0.0270\n",
      "epoch 529,loss 0.000151 cost 0.0266\n",
      "epoch 530,loss 0.000143 cost 0.0256\n",
      "epoch 531,loss 0.000144 cost 0.0299\n",
      "epoch 532,loss 0.000112 cost 0.0278\n",
      "epoch 533,loss 0.000092 cost 0.0259\n",
      "epoch 534,loss 0.000131 cost 0.0269\n",
      "epoch 535,loss 0.000183 cost 0.0261\n",
      "epoch 536,loss 0.000126 cost 0.0268\n",
      "epoch 537,loss 0.000086 cost 0.0268\n",
      "epoch 538,loss 0.000181 cost 0.0264\n",
      "epoch 539,loss 0.000130 cost 0.0260\n",
      "epoch 540,loss 0.000078 cost 0.0273\n",
      "epoch 541,loss 0.000078 cost 0.0267\n",
      "epoch 542,loss 0.000142 cost 0.0277\n",
      "epoch 543,loss 0.000140 cost 0.0264\n",
      "epoch 544,loss 0.000149 cost 0.0262\n",
      "epoch 545,loss 0.000167 cost 0.0261\n",
      "epoch 546,loss 0.000164 cost 0.0261\n",
      "epoch 547,loss 0.000100 cost 0.0271\n",
      "epoch 548,loss 0.000070 cost 0.0277\n",
      "epoch 549,loss 0.000088 cost 0.0262\n",
      "epoch 550,loss 0.000145 cost 0.0259\n",
      "epoch 551,loss 0.000095 cost 0.0259\n",
      "epoch 552,loss 0.000227 cost 0.0259\n",
      "epoch 553,loss 0.000141 cost 0.0263\n",
      "epoch 554,loss 0.000061 cost 0.0258\n",
      "epoch 555,loss 0.000103 cost 0.0278\n",
      "epoch 556,loss 0.000142 cost 0.0269\n",
      "epoch 557,loss 0.000080 cost 0.0260\n",
      "epoch 558,loss 0.000110 cost 0.0256\n",
      "epoch 559,loss 0.000131 cost 0.0264\n",
      "epoch 560,loss 0.000142 cost 0.0257\n",
      "epoch 561,loss 0.000167 cost 0.0275\n",
      "epoch 562,loss 0.000122 cost 0.0261\n",
      "epoch 563,loss 0.000064 cost 0.0297\n",
      "epoch 564,loss 0.000087 cost 0.0285\n",
      "epoch 565,loss 0.000114 cost 0.0278\n",
      "epoch 566,loss 0.000067 cost 0.0259\n",
      "epoch 567,loss 0.000042 cost 0.0264\n",
      "epoch 568,loss 0.000061 cost 0.0263\n",
      "epoch 569,loss 0.000097 cost 0.0265\n",
      "epoch 570,loss 0.000034 cost 0.0296\n",
      "epoch 571,loss 0.000054 cost 0.0277\n",
      "epoch 572,loss 0.000094 cost 0.0288\n",
      "epoch 573,loss 0.000092 cost 0.0270\n",
      "epoch 574,loss 0.000145 cost 0.0263\n",
      "epoch 575,loss 0.000063 cost 0.0258\n",
      "epoch 576,loss 0.000133 cost 0.0265\n",
      "epoch 577,loss 0.000115 cost 0.0268\n",
      "epoch 578,loss 0.000186 cost 0.0263\n",
      "epoch 579,loss 0.000069 cost 0.0286\n",
      "epoch 580,loss 0.000062 cost 0.0284\n",
      "epoch 581,loss 0.000092 cost 0.0270\n",
      "epoch 582,loss 0.000072 cost 0.0268\n",
      "epoch 583,loss 0.000112 cost 0.0259\n",
      "epoch 584,loss 0.000087 cost 0.0257\n",
      "epoch 585,loss 0.000047 cost 0.0261\n",
      "epoch 586,loss 0.000176 cost 0.0257\n",
      "epoch 587,loss 0.000134 cost 0.0263\n",
      "epoch 588,loss 0.000135 cost 0.0280\n",
      "epoch 589,loss 0.000025 cost 0.0263\n",
      "epoch 590,loss 0.000071 cost 0.0256\n",
      "epoch 591,loss 0.000093 cost 0.0253\n",
      "epoch 592,loss 0.000066 cost 0.0259\n",
      "epoch 593,loss 0.000128 cost 0.0258\n",
      "epoch 594,loss 0.000211 cost 0.0272\n",
      "epoch 595,loss 0.000065 cost 0.0270\n",
      "epoch 596,loss 0.000102 cost 0.0268\n",
      "epoch 597,loss 0.000087 cost 0.0260\n",
      "epoch 598,loss 0.000030 cost 0.0270\n",
      "epoch 599,loss 0.000072 cost 0.0270\n",
      "epoch 600,loss 0.000066 cost 0.0259\n",
      "epoch 601,loss 0.000044 cost 0.0252\n",
      "epoch 602,loss 0.000101 cost 0.0253\n",
      "epoch 603,loss 0.000074 cost 0.0280\n",
      "epoch 604,loss 0.000089 cost 0.0283\n",
      "epoch 605,loss 0.000121 cost 0.0260\n",
      "epoch 606,loss 0.000115 cost 0.0259\n",
      "epoch 607,loss 0.000058 cost 0.0257\n",
      "epoch 608,loss 0.000067 cost 0.0266\n",
      "epoch 609,loss 0.000144 cost 0.0254\n",
      "epoch 610,loss 0.000047 cost 0.0258\n",
      "epoch 611,loss 0.000083 cost 0.0282\n",
      "epoch 612,loss 0.000153 cost 0.0285\n",
      "epoch 613,loss 0.000180 cost 0.0284\n",
      "epoch 614,loss 0.000135 cost 0.0252\n",
      "epoch 615,loss 0.000172 cost 0.0257\n",
      "epoch 616,loss 0.000113 cost 0.0266\n",
      "epoch 617,loss 0.000035 cost 0.0259\n",
      "epoch 618,loss 0.000077 cost 0.0256\n",
      "epoch 619,loss 0.000084 cost 0.0287\n",
      "epoch 620,loss 0.000140 cost 0.0272\n",
      "epoch 621,loss 0.000114 cost 0.0260\n",
      "epoch 622,loss 0.000059 cost 0.0269\n",
      "epoch 623,loss 0.000104 cost 0.0280\n",
      "epoch 624,loss 0.000159 cost 0.0269\n",
      "epoch 625,loss 0.000174 cost 0.0263\n",
      "epoch 626,loss 0.000056 cost 0.0267\n",
      "epoch 627,loss 0.000078 cost 0.0273\n",
      "epoch 628,loss 0.000139 cost 0.0269\n",
      "epoch 629,loss 0.000063 cost 0.0253\n",
      "epoch 630,loss 0.000040 cost 0.0275\n",
      "epoch 631,loss 0.000124 cost 0.0284\n",
      "epoch 632,loss 0.000088 cost 0.0318\n",
      "epoch 633,loss 0.000074 cost 0.0282\n",
      "epoch 634,loss 0.000112 cost 0.0303\n",
      "epoch 635,loss 0.000016 cost 0.0299\n",
      "epoch 636,loss 0.000124 cost 0.0274\n",
      "epoch 637,loss 0.000054 cost 0.0263\n",
      "epoch 638,loss 0.000084 cost 0.0251\n",
      "epoch 639,loss 0.000075 cost 0.0248\n",
      "epoch 640,loss 0.000039 cost 0.0246\n",
      "epoch 641,loss 0.000088 cost 0.0252\n",
      "epoch 642,loss 0.000104 cost 0.0247\n",
      "epoch 643,loss 0.000088 cost 0.0256\n",
      "epoch 644,loss 0.000201 cost 0.0269\n",
      "epoch 645,loss 0.000074 cost 0.0260\n",
      "epoch 646,loss 0.000060 cost 0.0249\n",
      "epoch 647,loss 0.000050 cost 0.0260\n",
      "epoch 648,loss 0.000153 cost 0.0249\n",
      "epoch 649,loss 0.000078 cost 0.0250\n",
      "epoch 650,loss 0.000092 cost 0.0310\n",
      "epoch 651,loss 0.000185 cost 0.0288\n",
      "epoch 652,loss 0.000140 cost 0.0307\n",
      "epoch 653,loss 0.000064 cost 0.0264\n",
      "epoch 654,loss 0.000093 cost 0.0249\n",
      "epoch 655,loss 0.000150 cost 0.0300\n",
      "epoch 656,loss 0.000187 cost 0.0310\n",
      "epoch 657,loss 0.000082 cost 0.0291\n",
      "epoch 658,loss 0.000151 cost 0.0275\n",
      "epoch 659,loss 0.000072 cost 0.0267\n",
      "epoch 660,loss 0.000084 cost 0.0252\n",
      "epoch 661,loss 0.000077 cost 0.0250\n",
      "epoch 662,loss 0.000040 cost 0.0251\n",
      "epoch 663,loss 0.000169 cost 0.0271\n",
      "epoch 664,loss 0.000082 cost 0.0248\n",
      "epoch 665,loss 0.000129 cost 0.0256\n",
      "epoch 666,loss 0.000048 cost 0.0261\n",
      "epoch 667,loss 0.000108 cost 0.0265\n",
      "epoch 668,loss 0.000107 cost 0.0282\n",
      "epoch 669,loss 0.000090 cost 0.0258\n",
      "epoch 670,loss 0.000197 cost 0.0248\n",
      "epoch 671,loss 0.000075 cost 0.0258\n",
      "epoch 672,loss 0.000098 cost 0.0249\n",
      "epoch 673,loss 0.000173 cost 0.0265\n",
      "epoch 674,loss 0.000094 cost 0.0253\n",
      "epoch 675,loss 0.000090 cost 0.0260\n",
      "epoch 676,loss 0.000085 cost 0.0257\n",
      "epoch 677,loss 0.000043 cost 0.0250\n",
      "epoch 678,loss 0.000050 cost 0.0249\n",
      "epoch 679,loss 0.000101 cost 0.0252\n",
      "epoch 680,loss 0.000070 cost 0.0249\n",
      "epoch 681,loss 0.000065 cost 0.0248\n",
      "epoch 682,loss 0.000120 cost 0.0249\n",
      "epoch 683,loss 0.000072 cost 0.0251\n",
      "epoch 684,loss 0.000144 cost 0.0284\n",
      "epoch 685,loss 0.000126 cost 0.0268\n",
      "epoch 686,loss 0.000157 cost 0.0263\n",
      "epoch 687,loss 0.000069 cost 0.0256\n",
      "epoch 688,loss 0.000100 cost 0.0249\n",
      "epoch 689,loss 0.000083 cost 0.0249\n",
      "epoch 690,loss 0.000063 cost 0.0257\n",
      "epoch 691,loss 0.000102 cost 0.0270\n",
      "epoch 692,loss 0.000059 cost 0.0266\n",
      "epoch 693,loss 0.000070 cost 0.0280\n",
      "epoch 694,loss 0.000096 cost 0.0251\n",
      "epoch 695,loss 0.000146 cost 0.0254\n",
      "epoch 696,loss 0.000107 cost 0.0247\n",
      "epoch 697,loss 0.000070 cost 0.0254\n",
      "epoch 698,loss 0.000027 cost 0.0252\n",
      "epoch 699,loss 0.000072 cost 0.0250\n",
      "epoch 700,loss 0.000084 cost 0.0253\n",
      "epoch 701,loss 0.000095 cost 0.0280\n",
      "epoch 702,loss 0.000040 cost 0.0256\n",
      "epoch 703,loss 0.000096 cost 0.0255\n",
      "epoch 704,loss 0.000145 cost 0.0255\n",
      "epoch 705,loss 0.000050 cost 0.0263\n",
      "epoch 706,loss 0.000090 cost 0.0249\n",
      "epoch 707,loss 0.000066 cost 0.0256\n",
      "epoch 708,loss 0.000104 cost 0.0260\n",
      "epoch 709,loss 0.000117 cost 0.0259\n",
      "epoch 710,loss 0.000029 cost 0.0253\n",
      "epoch 711,loss 0.000104 cost 0.0252\n",
      "epoch 712,loss 0.000042 cost 0.0251\n",
      "epoch 713,loss 0.000081 cost 0.0251\n",
      "epoch 714,loss 0.000177 cost 0.0252\n",
      "epoch 715,loss 0.000079 cost 0.0252\n",
      "epoch 716,loss 0.000092 cost 0.0256\n",
      "epoch 717,loss 0.000065 cost 0.0280\n",
      "epoch 718,loss 0.000107 cost 0.0254\n",
      "epoch 719,loss 0.000083 cost 0.0248\n",
      "epoch 720,loss 0.000061 cost 0.0248\n",
      "epoch 721,loss 0.000176 cost 0.0263\n",
      "epoch 722,loss 0.000067 cost 0.0251\n",
      "epoch 723,loss 0.000081 cost 0.0267\n",
      "epoch 724,loss 0.000207 cost 0.0280\n",
      "epoch 725,loss 0.000097 cost 0.0257\n",
      "epoch 726,loss 0.000052 cost 0.0253\n",
      "epoch 727,loss 0.000160 cost 0.0248\n",
      "epoch 728,loss 0.000099 cost 0.0246\n",
      "epoch 729,loss 0.000187 cost 0.0248\n",
      "epoch 730,loss 0.000044 cost 0.0247\n",
      "epoch 731,loss 0.000084 cost 0.0245\n",
      "epoch 732,loss 0.000136 cost 0.0247\n",
      "epoch 733,loss 0.000200 cost 0.0299\n",
      "epoch 734,loss 0.000106 cost 0.0267\n",
      "epoch 735,loss 0.000132 cost 0.0248\n",
      "epoch 736,loss 0.000086 cost 0.0255\n",
      "epoch 737,loss 0.000115 cost 0.0249\n",
      "epoch 738,loss 0.000057 cost 0.0247\n",
      "epoch 739,loss 0.000094 cost 0.0246\n",
      "epoch 740,loss 0.000063 cost 0.0246\n",
      "epoch 741,loss 0.000085 cost 0.0249\n",
      "epoch 742,loss 0.000065 cost 0.0264\n",
      "epoch 743,loss 0.000160 cost 0.0272\n",
      "epoch 744,loss 0.000070 cost 0.0254\n",
      "epoch 745,loss 0.000153 cost 0.0265\n",
      "epoch 746,loss 0.000062 cost 0.0252\n",
      "epoch 747,loss 0.000080 cost 0.0253\n",
      "epoch 748,loss 0.000118 cost 0.0252\n",
      "epoch 749,loss 0.000045 cost 0.0263\n",
      "epoch 750,loss 0.000067 cost 0.0256\n",
      "epoch 751,loss 0.000173 cost 0.0265\n",
      "epoch 752,loss 0.000141 cost 0.0253\n",
      "epoch 753,loss 0.000090 cost 0.0251\n",
      "epoch 754,loss 0.000048 cost 0.0250\n",
      "epoch 755,loss 0.000095 cost 0.0247\n",
      "epoch 756,loss 0.000081 cost 0.0249\n",
      "epoch 757,loss 0.000113 cost 0.0250\n",
      "epoch 758,loss 0.000283 cost 0.0251\n",
      "epoch 759,loss 0.000071 cost 0.0275\n",
      "epoch 760,loss 0.000128 cost 0.0249\n",
      "epoch 761,loss 0.000061 cost 0.0258\n",
      "epoch 762,loss 0.000143 cost 0.0248\n",
      "epoch 763,loss 0.000109 cost 0.0248\n",
      "epoch 764,loss 0.000060 cost 0.0246\n",
      "epoch 765,loss 0.000093 cost 0.0269\n",
      "epoch 766,loss 0.000065 cost 0.0264\n",
      "epoch 767,loss 0.000186 cost 0.0268\n",
      "epoch 768,loss 0.000151 cost 0.0260\n",
      "epoch 769,loss 0.000047 cost 0.0260\n",
      "epoch 770,loss 0.000119 cost 0.0247\n",
      "epoch 771,loss 0.000114 cost 0.0247\n",
      "epoch 772,loss 0.000155 cost 0.0255\n",
      "epoch 773,loss 0.000064 cost 0.0254\n",
      "epoch 774,loss 0.000059 cost 0.0255\n",
      "epoch 775,loss 0.000148 cost 0.0264\n",
      "epoch 776,loss 0.000161 cost 0.0257\n",
      "epoch 777,loss 0.000089 cost 0.0257\n",
      "epoch 778,loss 0.000108 cost 0.0247\n",
      "epoch 779,loss 0.000109 cost 0.0246\n",
      "epoch 780,loss 0.000063 cost 0.0248\n",
      "epoch 781,loss 0.000115 cost 0.0249\n",
      "epoch 782,loss 0.000078 cost 0.0269\n",
      "epoch 783,loss 0.000133 cost 0.0269\n",
      "epoch 784,loss 0.000075 cost 0.0250\n",
      "epoch 785,loss 0.000170 cost 0.0248\n",
      "epoch 786,loss 0.000067 cost 0.0256\n",
      "epoch 787,loss 0.000041 cost 0.0247\n",
      "epoch 788,loss 0.000059 cost 0.0249\n",
      "epoch 789,loss 0.000106 cost 0.0248\n",
      "epoch 790,loss 0.000067 cost 0.0249\n",
      "epoch 791,loss 0.000040 cost 0.0257\n",
      "epoch 792,loss 0.000240 cost 0.0252\n",
      "epoch 793,loss 0.000030 cost 0.0248\n",
      "epoch 794,loss 0.000054 cost 0.0246\n",
      "epoch 795,loss 0.000067 cost 0.0247\n",
      "epoch 796,loss 0.000043 cost 0.0248\n",
      "epoch 797,loss 0.000016 cost 0.0247\n",
      "epoch 798,loss 0.000133 cost 0.0246\n",
      "epoch 799,loss 0.000041 cost 0.0256\n",
      "epoch 800,loss 0.000086 cost 0.0253\n",
      "epoch 801,loss 0.000132 cost 0.0248\n",
      "epoch 802,loss 0.000182 cost 0.0247\n",
      "epoch 803,loss 0.000149 cost 0.0247\n",
      "epoch 804,loss 0.000116 cost 0.0248\n",
      "epoch 805,loss 0.000065 cost 0.0248\n",
      "epoch 806,loss 0.000071 cost 0.0246\n",
      "epoch 807,loss 0.000114 cost 0.0247\n",
      "epoch 808,loss 0.000093 cost 0.0264\n",
      "epoch 809,loss 0.000066 cost 0.0249\n",
      "epoch 810,loss 0.000130 cost 0.0247\n",
      "epoch 811,loss 0.000090 cost 0.0254\n",
      "epoch 812,loss 0.000100 cost 0.0283\n",
      "epoch 813,loss 0.000085 cost 0.0258\n",
      "epoch 814,loss 0.000177 cost 0.0253\n",
      "epoch 815,loss 0.000102 cost 0.0247\n",
      "epoch 816,loss 0.000154 cost 0.0261\n",
      "epoch 817,loss 0.000172 cost 0.0268\n",
      "epoch 818,loss 0.000043 cost 0.0253\n",
      "epoch 819,loss 0.000157 cost 0.0251\n",
      "epoch 820,loss 0.000104 cost 0.0256\n",
      "epoch 821,loss 0.000203 cost 0.0252\n",
      "epoch 822,loss 0.000095 cost 0.0251\n",
      "epoch 823,loss 0.000130 cost 0.0249\n",
      "epoch 824,loss 0.000178 cost 0.0260\n",
      "epoch 825,loss 0.000152 cost 0.0262\n",
      "epoch 826,loss 0.000102 cost 0.0250\n",
      "epoch 827,loss 0.000057 cost 0.0296\n",
      "epoch 828,loss 0.000128 cost 0.0250\n",
      "epoch 829,loss 0.000063 cost 0.0283\n",
      "epoch 830,loss 0.000070 cost 0.0255\n",
      "epoch 831,loss 0.000129 cost 0.0252\n",
      "epoch 832,loss 0.000209 cost 0.0276\n",
      "epoch 833,loss 0.000129 cost 0.0260\n",
      "epoch 834,loss 0.000075 cost 0.0251\n",
      "epoch 835,loss 0.000103 cost 0.0249\n",
      "epoch 836,loss 0.000195 cost 0.0256\n",
      "epoch 837,loss 0.000183 cost 0.0260\n",
      "epoch 838,loss 0.000139 cost 0.0247\n",
      "epoch 839,loss 0.000039 cost 0.0257\n",
      "epoch 840,loss 0.000096 cost 0.0272\n",
      "epoch 841,loss 0.000109 cost 0.0271\n",
      "epoch 842,loss 0.000112 cost 0.0267\n",
      "epoch 843,loss 0.000035 cost 0.0265\n",
      "epoch 844,loss 0.000203 cost 0.0250\n",
      "epoch 845,loss 0.000084 cost 0.0249\n",
      "epoch 846,loss 0.000056 cost 0.0251\n",
      "epoch 847,loss 0.000152 cost 0.0249\n",
      "epoch 848,loss 0.000045 cost 0.0264\n",
      "epoch 849,loss 0.000110 cost 0.0270\n",
      "epoch 850,loss 0.000056 cost 0.0248\n",
      "epoch 851,loss 0.000049 cost 0.0249\n",
      "epoch 852,loss 0.000090 cost 0.0247\n",
      "epoch 853,loss 0.000069 cost 0.0248\n",
      "epoch 854,loss 0.000146 cost 0.0261\n",
      "epoch 855,loss 0.000104 cost 0.0249\n",
      "epoch 856,loss 0.000070 cost 0.0255\n",
      "epoch 857,loss 0.000090 cost 0.0278\n",
      "epoch 858,loss 0.000111 cost 0.0256\n",
      "epoch 859,loss 0.000102 cost 0.0259\n",
      "epoch 860,loss 0.000048 cost 0.0259\n",
      "epoch 861,loss 0.000064 cost 0.0249\n",
      "epoch 862,loss 0.000092 cost 0.0248\n",
      "epoch 863,loss 0.000180 cost 0.0251\n",
      "epoch 864,loss 0.000139 cost 0.0254\n",
      "epoch 865,loss 0.000040 cost 0.0258\n",
      "epoch 866,loss 0.000062 cost 0.0256\n",
      "epoch 867,loss 0.000057 cost 0.0250\n",
      "epoch 868,loss 0.000035 cost 0.0247\n",
      "epoch 869,loss 0.000151 cost 0.0247\n",
      "epoch 870,loss 0.000181 cost 0.0245\n",
      "epoch 871,loss 0.000061 cost 0.0248\n",
      "epoch 872,loss 0.000119 cost 0.0247\n",
      "epoch 873,loss 0.000060 cost 0.0277\n",
      "epoch 874,loss 0.000099 cost 0.0256\n",
      "epoch 875,loss 0.000045 cost 0.0251\n",
      "epoch 876,loss 0.000093 cost 0.0251\n",
      "epoch 877,loss 0.000175 cost 0.0248\n",
      "epoch 878,loss 0.000149 cost 0.0253\n",
      "epoch 879,loss 0.000189 cost 0.0249\n",
      "epoch 880,loss 0.000094 cost 0.0250\n",
      "epoch 881,loss 0.000175 cost 0.0249\n",
      "epoch 882,loss 0.000122 cost 0.0290\n",
      "epoch 883,loss 0.000087 cost 0.0251\n",
      "epoch 884,loss 0.000143 cost 0.0249\n",
      "epoch 885,loss 0.000111 cost 0.0265\n",
      "epoch 886,loss 0.000119 cost 0.0248\n",
      "epoch 887,loss 0.000162 cost 0.0246\n",
      "epoch 888,loss 0.000048 cost 0.0245\n",
      "epoch 889,loss 0.000203 cost 0.0250\n",
      "epoch 890,loss 0.000149 cost 0.0256\n",
      "epoch 891,loss 0.000062 cost 0.0247\n",
      "epoch 892,loss 0.000075 cost 0.0246\n",
      "epoch 893,loss 0.000118 cost 0.0245\n",
      "epoch 894,loss 0.000153 cost 0.0246\n",
      "epoch 895,loss 0.000184 cost 0.0248\n",
      "epoch 896,loss 0.000079 cost 0.0246\n",
      "epoch 897,loss 0.000092 cost 0.0247\n",
      "epoch 898,loss 0.000067 cost 0.0300\n",
      "epoch 899,loss 0.000097 cost 0.0266\n",
      "epoch 900,loss 0.000212 cost 0.0248\n",
      "epoch 901,loss 0.000205 cost 0.0259\n",
      "epoch 902,loss 0.000094 cost 0.0272\n",
      "epoch 903,loss 0.000132 cost 0.0248\n",
      "epoch 904,loss 0.000035 cost 0.0247\n",
      "epoch 905,loss 0.000023 cost 0.0246\n",
      "epoch 906,loss 0.000077 cost 0.0271\n",
      "epoch 907,loss 0.000185 cost 0.0268\n",
      "epoch 908,loss 0.000167 cost 0.0275\n",
      "epoch 909,loss 0.000067 cost 0.0283\n",
      "epoch 910,loss 0.000214 cost 0.0256\n",
      "epoch 911,loss 0.000166 cost 0.0249\n",
      "epoch 912,loss 0.000062 cost 0.0253\n",
      "epoch 913,loss 0.000030 cost 0.0247\n",
      "epoch 914,loss 0.000199 cost 0.0264\n",
      "epoch 915,loss 0.000114 cost 0.0270\n",
      "epoch 916,loss 0.000065 cost 0.0251\n",
      "epoch 917,loss 0.000067 cost 0.0253\n",
      "epoch 918,loss 0.000086 cost 0.0250\n",
      "epoch 919,loss 0.000076 cost 0.0249\n",
      "epoch 920,loss 0.000159 cost 0.0250\n",
      "epoch 921,loss 0.000075 cost 0.0249\n",
      "epoch 922,loss 0.000140 cost 0.0265\n",
      "epoch 923,loss 0.000081 cost 0.0276\n",
      "epoch 924,loss 0.000170 cost 0.0261\n",
      "epoch 925,loss 0.000158 cost 0.0262\n",
      "epoch 926,loss 0.000157 cost 0.0248\n",
      "epoch 927,loss 0.000148 cost 0.0247\n",
      "epoch 928,loss 0.000126 cost 0.0247\n",
      "epoch 929,loss 0.000086 cost 0.0250\n",
      "epoch 930,loss 0.000121 cost 0.0259\n",
      "epoch 931,loss 0.000105 cost 0.0276\n",
      "epoch 932,loss 0.000104 cost 0.0252\n",
      "epoch 933,loss 0.000114 cost 0.0258\n",
      "epoch 934,loss 0.000124 cost 0.0272\n",
      "epoch 935,loss 0.000065 cost 0.0248\n",
      "epoch 936,loss 0.000056 cost 0.0249\n",
      "epoch 937,loss 0.000073 cost 0.0251\n",
      "epoch 938,loss 0.000202 cost 0.0257\n",
      "epoch 939,loss 0.000135 cost 0.0274\n",
      "epoch 940,loss 0.000093 cost 0.0278\n",
      "epoch 941,loss 0.000199 cost 0.0257\n",
      "epoch 942,loss 0.000116 cost 0.0257\n",
      "epoch 943,loss 0.000091 cost 0.0247\n",
      "epoch 944,loss 0.000091 cost 0.0247\n",
      "epoch 945,loss 0.000154 cost 0.0269\n",
      "epoch 946,loss 0.000194 cost 0.0260\n",
      "epoch 947,loss 0.000112 cost 0.0282\n",
      "epoch 948,loss 0.000176 cost 0.0256\n",
      "epoch 949,loss 0.000198 cost 0.0256\n",
      "epoch 950,loss 0.000054 cost 0.0249\n",
      "epoch 951,loss 0.000033 cost 0.0252\n",
      "epoch 952,loss 0.000054 cost 0.0249\n",
      "epoch 953,loss 0.000178 cost 0.0267\n",
      "epoch 954,loss 0.000142 cost 0.0265\n",
      "epoch 955,loss 0.000200 cost 0.0289\n",
      "epoch 956,loss 0.000072 cost 0.0268\n",
      "epoch 957,loss 0.000087 cost 0.0265\n",
      "epoch 958,loss 0.000127 cost 0.0255\n",
      "epoch 959,loss 0.000157 cost 0.0253\n",
      "epoch 960,loss 0.000072 cost 0.0257\n",
      "epoch 961,loss 0.000092 cost 0.0251\n",
      "epoch 962,loss 0.000063 cost 0.0259\n",
      "epoch 963,loss 0.000113 cost 0.0258\n",
      "epoch 964,loss 0.000123 cost 0.0267\n",
      "epoch 965,loss 0.000117 cost 0.0259\n",
      "epoch 966,loss 0.000087 cost 0.0250\n",
      "epoch 967,loss 0.000142 cost 0.0253\n",
      "epoch 968,loss 0.000162 cost 0.0251\n",
      "epoch 969,loss 0.000023 cost 0.0255\n",
      "epoch 970,loss 0.000179 cost 0.0255\n",
      "epoch 971,loss 0.000153 cost 0.0269\n",
      "epoch 972,loss 0.000105 cost 0.0256\n",
      "epoch 973,loss 0.000051 cost 0.0264\n",
      "epoch 974,loss 0.000066 cost 0.0248\n",
      "epoch 975,loss 0.000103 cost 0.0248\n",
      "epoch 976,loss 0.000098 cost 0.0273\n",
      "epoch 977,loss 0.000059 cost 0.0250\n",
      "epoch 978,loss 0.000089 cost 0.0273\n",
      "epoch 979,loss 0.000172 cost 0.0268\n",
      "epoch 980,loss 0.000148 cost 0.0260\n",
      "epoch 981,loss 0.000087 cost 0.0252\n",
      "epoch 982,loss 0.000070 cost 0.0266\n",
      "epoch 983,loss 0.000089 cost 0.0252\n",
      "epoch 984,loss 0.000125 cost 0.0247\n",
      "epoch 985,loss 0.000061 cost 0.0250\n",
      "epoch 986,loss 0.000063 cost 0.0262\n",
      "epoch 987,loss 0.000103 cost 0.0334\n",
      "epoch 988,loss 0.000118 cost 0.0287\n",
      "epoch 989,loss 0.000123 cost 0.0248\n",
      "epoch 990,loss 0.000141 cost 0.0254\n",
      "epoch 991,loss 0.000145 cost 0.0262\n",
      "epoch 992,loss 0.000089 cost 0.0249\n",
      "epoch 993,loss 0.000141 cost 0.0248\n",
      "epoch 994,loss 0.000060 cost 0.0278\n",
      "epoch 995,loss 0.000114 cost 0.0259\n",
      "epoch 996,loss 0.000131 cost 0.0251\n",
      "epoch 997,loss 0.000125 cost 0.0251\n",
      "epoch 998,loss 0.000078 cost 0.0250\n",
      "epoch 999,loss 0.000085 cost 0.0258\n",
      "epoch 1000,loss 0.000104 cost 0.0248\n",
      "epoch 1001,loss 0.000086 cost 0.0254\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "source": [
    "print(net.linear.bias,':',true_b)\n",
    "print(net.linear.weight,':',true_w)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Parameter containing:\n",
      "tensor([4.1999], device='cuda:0', requires_grad=True) : 4.2\n",
      "Parameter containing:\n",
      "tensor([[ 2.0000, -3.3995]], device='cuda:0', requires_grad=True) : [2, -3.4]\n"
     ]
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "2b23fc4612d2a20491382ea15c73e42619afc437d67ed04c4074dd835ed863ea"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.6.8 64-bit ('torch': conda)"
  },
  "language_info": {
   "name": "python",
   "version": "3.6.8",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}